package textapp.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import textapp.dao.model.User;

public class EMUtil {
	private static final EntityManagerFactory entityManagerFactory;
	
	static {
		entityManagerFactory = Persistence.createEntityManagerFactory( "org.tommy.textapp.jpa" );
	}
	
	public static EntityManagerFactory getEMFactory() {
		return entityManagerFactory;
	}
	
	public static EntityManager createEntityManager() {
		return entityManagerFactory.createEntityManager();
	}
	
	public static void main(String[] args) { 
		EntityManager em = EMUtil.createEntityManager();
		User u = em.find(User.class, 1);
		System.out.println(u);
		em.close();
	}
}
